﻿@*page:LoginLog.razor*@
@*gardener-time:2024-07-01 14:54:27*@
@page "/system_manager/login-log"
@using Gardener.Core.Authorization.Enums
@using Gardener.Core.Authorization.Resources
@inherits ListOperateTableBase<LoginLogDto, long, LoginLogEdit,AuthorizationLocalResource>

@{
    TableFilter<IdentityType>[] identityTypeEnumFilters = EnumHelper.EnumToList<IdentityType>().Select(x => { return new TableFilter<IdentityType>() { Text = Localizer[EnumHelper.GetEnumDescriptionOrName(x)], Value = x }; }).ToArray();

    TableFilter<LoginClientType>[] loginClientTypeEnumFilters = EnumHelper.EnumToList<LoginClientType>().Select(x => { return new TableFilter<LoginClientType>() { Text = Localizer[EnumHelper.GetEnumDescriptionOrName(x)], Value = x }; }).ToArray();

    TableFilter<LoginStatus>[] loginStatusEnumFilters = EnumHelper.EnumToList<LoginStatus>().Select(x => { return new TableFilter<LoginStatus>() { Text = Localizer[EnumHelper.GetEnumDescriptionOrName(x)], Value = x }; }).ToArray();

    TableFilter<LoginFailReason?>[] loginFailReasonEnumFilters = EnumHelper.EnumToList<LoginFailReason>().Select(x => { return new TableFilter<LoginFailReason?>() { Text = Localizer[EnumHelper.GetEnumDescriptionOrName(x)], Value = x }; }).ToArray();
}
<div>
    <Table @ref="_table"
           TItem="LoginLogDto"
           DataSource="_datas"
           Total="_total"
           OnChange="OnChange"
           @bind-PageSize="_pageSize"
           @bind-SelectedRows="_selectedRows"
           Loading="_tableLoading.Value"
           Context="model"
           Size="ClientConstant.DefaultTableSize"
           PaginationPosition="@ClientConstant.TablePaginationPosition"
           RowKey="x => x.Id"
           RemoteDataSource>
        <TitleTemplate>
            <ResourceAuthorize ResourceKey="auth_login_log_search">
                <TableSearch TDto="LoginLogDto" @ref="this._tableSearch" OnSearch="OnTableSearch" Settings="_tableSearchSettings" CustomLocalizer="Localizer" />
            </ResourceAuthorize>
            <Row>
                <AntDesign.Col Span="8">
                    <ResourceAuthorize ResourceKey="auth_login_log_delete_selected">
                        <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Delete" Danger OnClick="OnClickDeletes" Loading="_deletesBtnLoading">
                            @Localizer[nameof(SharedLocalResource.DeleteSelected)]
                        </Button>
                    </ResourceAuthorize>
                </AntDesign.Col>
                <AntDesign.Col Span="16" Style="text-align:right">
                    <Space>
                        <ResourceAuthorize ResourceKey="auth_login_log_refresh">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Reload" OnClick="ReLoadTable">
                                    @Localizer[nameof(SharedLocalResource.Refresh)]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                    </Space>
                </AntDesign.Col>
            </Row>
        </TitleTemplate>
        <ColumnDefinitions>
            <Selection Hidden="@_userUnauthorizedResources["auth_login_log_delete_selected"]" />
            <PropertyColumn Property="x => x.Id" Filterable Sortable />
            <PropertyColumn Property="x => x.TenantId" Filters="_tenantFilters" Filterable Title="@Localizer[nameof(SharedLocalResource.Tenant)]" Hidden="@_userUnauthorizedResources[CommonResourceKeys.SystemTenantAdministratorKey]">
                <span>@model.Tenant?.Name</span>
            </PropertyColumn>
            <PropertyColumn Property="x => x.IdentityId" Filterable Sortable />
            <PropertyColumn Property="x => x.IdentityName" Filterable Sortable />
            <PropertyColumn Property="x => x.IdentityType" Filterable Sortable Filters="identityTypeEnumFilters">
                <TagPro Text="@model.IdentityType" Localizer="Localizer"></TagPro>
            </PropertyColumn>
            <PropertyColumn Property="x => x.LoginId" Filterable Sortable>
                <GuidView StringValue="@model.LoginId"></GuidView>
            </PropertyColumn>
            <PropertyColumn Property="x => x.LoginClientType" Filterable Sortable Filters="loginClientTypeEnumFilters">
                <TagPro Text="@model.LoginClientType" Localizer="Localizer"></TagPro>
            </PropertyColumn>
            <PropertyColumn Property="x => x.LoginStatus" Filterable Sortable Filters="loginStatusEnumFilters">
                <TagPro Text="@model.LoginStatus" Localizer="Localizer"></TagPro>
            </PropertyColumn>
            <PropertyColumn Property="x => x.LoginFailReason" Filterable Sortable Filters="loginFailReasonEnumFilters">
                <TagPro Text="@model.LoginFailReason" Localizer="Localizer"></TagPro>
            </PropertyColumn>
            <PropertyColumn Property="x => x.ClientName" Filterable />
            <PropertyColumn Property="x => x.ClientVersion" Filterable />
            <PropertyColumn Property="x => x.Ip" Filterable Sortable />
            <PropertyColumn Property="x => x.LoginTime" Sortable Format="@ClientConstant.DateTimeFormat" />
            <PropertyColumn Property="x => x.CreatedTime" Sortable DefaultSortOrder="@SortDirection.Descending" Format="@ClientConstant.DateTimeFormat" />
            <ActionColumn>
                <Space>
                    <ResourceAuthorize ResourceKey="auth_login_log_detail">
                        <SpaceItem>
                            <Tooltip Title="@Localizer[nameof(SharedLocalResource.Detail)]" ArrowPointAtCenter="true">
                                <Button Icon="@IconType.Outline.Eye" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="() => OnClickDetail(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="auth_login_log_delete">
                        <SpaceItem>
                            <Tooltip Title="@Localizer[nameof(SharedLocalResource.Delete)]" ArrowPointAtCenter="true">
                                <Button Icon="@IconType.Outline.Delete" Type="@ButtonType.Primary" Danger OnClick="() => OnClickDelete(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                </Space>
            </ActionColumn>
        </ColumnDefinitions>
    </Table>
</div>